<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Structure and Interpretation of Computer Programs, 2e: Chapter 3</title>

<meta name="description" content="Structure and Interpretation of Computer Programs, 2e: Chapter 3" />
<meta name="keywords" content="Structure and Interpretation of Computer Programs, 2e: Chapter 3" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="Generator" content="texi2any" />
<meta charset="utf-8" />
<link href="index.xhtml#Top" rel="start" title="Top" />
<link href="Term-Index.xhtml#Term-Index" rel="index" title="Term Index" />
<link href="index.xhtml#SEC_Contents" rel="contents" title="Table of Contents" />
<link href="index.xhtml#Top" rel="prev" title="Top" />
<link href="3_002e1.xhtml#g_t3_002e1" rel="next" title="3.1" />
<link href="2_002e5.xhtml#g_t2_002e5_002e3" rel="prev" title="2.5.3" />

<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/prettify.css" rel="stylesheet" type="text/css" />

<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/footnotes.js" type="text/javascript"></script>
<script src="js/browsertest.js" type="text/javascript"></script>
</head>

<body>
<section><span class="top jump" title="Jump to top"><a href="#pagetop" accesskey="t">⇡</a></span><a id="pagetop"></a><a id="Chapter-3"></a>
<nav class="header">
<p>
Next: <a href="3_002e1.xhtml#g_t3_002e1" accesskey="n" rel="next">3.1</a>, Prev: <a href="2_002e5.xhtml#g_t2_002e5" accesskey="p" rel="prev">2.5</a>, Up: <a href="index.xhtml#Top" accesskey="u" rel="prev">Top</a>   [<a href="index.xhtml#SEC_Contents" title="Table of contents" accesskey="c" rel="contents">Contents</a>]</p>
</nav>
<a id="Modularity_002c-Objects_002c-and-State"></a>
<h2 class="chapter"><span class="chapnum">3</span><span class="chaptitle">Modularity, Objects, and State</span></h2>

<blockquote>
<p>Mεταβάλλον ὰναπαύεται<br />
(Even while it changes, it stands still.)<br />
—Heraclitus
</p>
<p>Plus ça change, plus c’est la même chose.<br />
—Alphonse Karr
</p></blockquote>

<p>The preceding chapters introduced the basic elements from which programs are
made.  We saw how primitive procedures and primitive data are combined to
construct compound entities, and we learned that abstraction is vital in
helping us to cope with the complexity of large systems.  But these tools are
not sufficient for designing programs.  Effective program synthesis also
requires organizational principles that can guide us in formulating the overall
design of a program.  In particular, we need strategies to help us structure
large systems so that they will be <a id="index-modular"></a>
<em>modular</em>, that is, so that they can
be divided “naturally” into coherent parts that can be separately developed
and maintained.
</p>
<p>One powerful design strategy, which is particularly appropriate to the
construction of programs for modeling physical systems, is to base the
structure of our programs on the structure of the system being modeled.  For
each object in the system, we construct a corresponding computational object.
For each system action, we define a symbolic operation in our computational
model.  Our hope in using this strategy is that extending the model to
accommodate new objects or new actions will require no strategic changes to the
program, only the addition of the new symbolic analogs of those objects or
actions.  If we have been successful in our system organization, then to add a
new feature or debug an old one we will have to work on only a localized part
of the system.
</p>
<p>To a large extent, then, the way we organize a large program is dictated by our
perception of the system to be modeled.  In this chapter we will investigate
two prominent organizational strategies arising from two rather different
“world views” of the structure of systems.  The first organizational strategy
concentrates on <a id="index-objects"></a>
<em>objects</em>, viewing a large system as a collection of
distinct objects whose behaviors may change over time.  An alternative
organizational strategy concentrates on the <a id="index-streams"></a>
<em>streams</em> of information
that flow in the system, much as an electrical engineer views a
signal-processing system.
</p>
<p>Both the object-based approach and the stream-processing approach raise
significant linguistic issues in programming.  With objects, we must be
concerned with how a computational object can change and yet maintain its
identity.  This will force us to abandon our old substitution model of
computation (<a href="1_002e1.xhtml#g_t1_002e1_002e5">1.1.5</a>) in favor of a more mechanistic but less
theoretically tractable <a id="index-environment-model"></a>
<em>environment model</em> of computation.  The
difficulties of dealing with objects, change, and identity are a fundamental
consequence of the need to grapple with time in our computational models.
These difficulties become even greater when we allow the possibility of
concurrent execution of programs.  The stream approach can be most fully
exploited when we decouple simulated time in our model from the order of the
events that take place in the computer during evaluation.  We will accomplish
this using a technique known as <a id="index-delayed-evaluation"></a>
<em>delayed evaluation</em>.
</p>

<nav class="header">
<p>
Next: <a href="3_002e1.xhtml#g_t3_002e1" accesskey="n" rel="next">3.1</a>, Prev: <a href="2_002e5.xhtml#g_t2_002e5" accesskey="p" rel="prev">2.5</a>, Up: <a href="index.xhtml#Top" accesskey="u" rel="prev">Top</a>   [<a href="index.xhtml#SEC_Contents" title="Table of contents" accesskey="c" rel="contents">Contents</a>]</p>
</nav>


</section><span class="bottom jump" title="Jump to bottom"><a href="#pagebottom" accesskey="b">⇣</a></span><a id="pagebottom"></a>
</body>
</html>